package com.yigang.controller;

import java.text.ParseException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yigang.entity.Exercise;
import com.yigang.service.ActivityService;

import com.yigang.utils.ResultUtil;

/**
 * @author 陈佳祥
 *活动关联商品   管理
 */
@Controller
@RequestMapping("/activity")
public class ActivityController {
	@Autowired
	private ActivityService activityService;
	//增删改查方法
	@RequestMapping("activityList")
	public String activityList() {
		return "jsp/activity/activityList";
	}
	@RequestMapping("addActivity")
	public String addActivity() {
		return "jsp/activity/addActivity";
	}

	@RequestMapping("editActivity/{activity_id}")
	public String editActivity(@PathVariable("activity_id") int activity_id, HttpSession session) {
		Exercise activity = activityService.selectActivityById(activity_id);

		session.setAttribute("activity", activity);
		return "jsp/activity/editActivity";
	}

	//添加活动关联商品
	@RequestMapping("insertActivity")
	@ResponseBody
	public ResultUtil insertProduct(Exercise record) {
		activityService.insertSelective(record);
		return ResultUtil.ok();

	}

	@RequestMapping("deleteActivityById")
	@ResponseBody
	public ResultUtil deleteActivityById(int activity_id) {
		
		return activityService.deleteByPrimaryKey(activity_id);
	}

	@RequestMapping("getActivityList")
	@ResponseBody
	public ResultUtil getProductList(Integer page, Integer limit, Exercise record) {

		return activityService.selectActivityList(page, limit, record);
	}

	@RequestMapping("updateActivity")
	@ResponseBody
	public ResultUtil updateActivity(Exercise record) throws ParseException {
		
		return activityService.updateByPrimaryKeySelective(record);
	}
}
